from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.select import Select


class BasePage:

    # driver 浏览器驱动
    # by_type 定位元素类型
    # by_value  定位元素类型对应的值
    def findElement(self, driver: WebDriver, by_type: str, by_value) -> WebElement:
        by_type = by_type.lower()
        by = None
        if "id" == by_type:
            by = By.ID
        elif "name" == by_type:
            by = By.NAME
        elif "class" == by_type:
            by = By.CLASS_NAME
        elif "tag" == by_type:
            by = By.TAG_NAME
        elif "link" == by_type:
            by = By.LINK_TEXT
        elif "partial_link" == by_type:
            by = By.PARTIAL_LINK_TEXT
        elif "css" == by_type:
            by = By.CSS_SELECTOR
        elif "xpath" == by_type:
            by = By.XPATH

        et = driver.find_element(by, by_value)
        return et
